<?php
/*	
	审核分销商
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();

$tabs=array(
	array('op'=>'list','title'=>'申请解绑记录'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('jiestorelog',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员','type'=>'member'),
			array('name'=>'createtime','title'=>'申请时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'apply_status'),
			array('name'=>'complete_time','title'=>'审核时间','type'=>'time'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal','op'=>'check','title'=>'审核','show'=>array('status'=>array(0,2))),
		)),
		'search'=>array(
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'状态','options'=>'apply_status'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
			
		),
	);
	$return['htmls']=$htmls;
	$return['apply_status']=$this->apply_status;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$apply_id=intval($post['id']);
		$status=intval($post['status']);
		if(!$status){
			exi('请选择审核通过还是不通过！','error');
		}
		$this->model('member')->check_jiestore($apply_id,$status,$post['remark']);
		exi('处理成功！','','/jiestorelog/list/');
	}
	$item=$this->get('jiestorelog',array('id'=>intval($_RQ['id'])));
	if(!$item){
		exi('指定结算单不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'门店解绑申请',
		'edit'=>array(
			array('name'=>'status','title'=>'审核','type'=>'radio','options'=>'apply_status'),
			array('name'=>'remark','title'=>'不通过原因','type'=>'text','show'=>array('status'=>2)),
		),
	);
	$return['apply_status']=$this->apply_status;
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		$this->delete('jiestorelog',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('jiestorelog',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}